<template>
    <div class="content-main">
        <div class="breadcrumb">
            <div class="breadcrumb-icon">
                <img src="./../../assets/images/breadcrumb_icon.png" />
            </div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>虚机配置</el-breadcrumb-item>
            </el-breadcrumb>
            <!-- <bread-crumb-back></bread-crumb-back> -->
        </div>
        <div class="content-box">
            <div class="search-box">
                <div class="search-item">
                    <span class="search-title">案例名称: </span>
                    <el-input v-model="projectName" placeholder="请输入案例名称" style="float:left; width:auto;"></el-input>
                </div>
                <div class="search-item">
                    <span class="search-title">案例类型: </span>
                    <el-select
                        v-model="projectTypeValue"
                        placeholder="请选择案例"
                        value-key="value"
                        style="float:left;">
                        <el-option
                        v-for="item in projectTypeStatus"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <div class="search-item">
                    <el-button type="primary" @click="searchFn">搜索</el-button>
                </div>
            </div>
            <div class="project-config-list">
                <ul class="list-ul">
                    <li v-for="(item, index) in listData">
                        <div class="config-list-header">
                            <div class="config-list-img">
                                <i class="iconfont" :style="{ color: item.colour }" :class="item.picName"></i>
                            </div>
                            <span>{{ item.projectName }}</span>
                            <p :title="item.userName">{{item.userName}}</p>
                        </div>
                        <div class="config-list-info" v-if="item.id != null">
                            <div class="info-title">
                                配置类型：{{ item.isCluster == 0 ? '单机配置' : '集群配置' }}
                            </div>
                            <div class="info-content">
                                <div class="info-item">
                                    主机镜像：{{ item.mainImageName }} cpu上限：{{ item.mainCpu }} 核 内存上限：{{ item.mainMemory }}G
                                </div>
                                <div class="info-item" v-for="(item2, index2) in item.cluster">
                                    从机{{index2+1}}镜像：{{ item2.imageName }}  cpu上限：{{ item2.cpu }} 核 内存上限：{{ item2.memory }}G
                                </div>
                            </div>
                        </div>
                        <div v-else class="config-list-add" :style="{ color: item.colour}" @click="addFn(item.projectId)">+</div>
                        <!-- <div class="config-list-tag" :style="{ background: item.colour}">
                            {{ item.userName }}
                        </div> -->
                        <el-button class="config-btn" v-if="item.id != null" :style="{ background: item.colour}" type="primary" @click="modifyFn(item)">修改</el-button>
                        <el-button class="config-btn" v-else type="primary" :style="{ background: item.colour}" @click="addFn(item.projectId)">添加</el-button>
                    </li>
                </ul>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="pagesize"
                    layout="total, prev, pager, next, jumper"
                    :total="totalCount"
                    style="margin-top: 20px; text-align: center;">
                </el-pagination>
            </div>
            <el-dialog class="add-virtual-dialog" :title="addVirtualTitle" :visible.sync="dialogFormVisible" width='500px'>
                <el-form :model="form" :rules="rules" ref="form" label-width="130px">
                    <el-form-item label="类型 :">
                        <el-radio-group v-model="form.radioType" @change="init">
                            <el-radio :label="0">单节点</el-radio>
                            <el-radio :label="1">集群</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="来源 :" v-if="form.radioType == 0">
                        <el-radio-group v-model="form.radioSource" @change="init">
                            <el-radio :label="1">系统预置</el-radio>
                            <el-radio :label="0">教师制作</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <div>
                        <el-form-item v-if="form.radioType == 0" label="镜像名称 :" prop="mirrorValue">
                            <el-select
                                v-model="form.mirrorValue"
                                placeholder="请选择镜像"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.mirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item v-if="form.radioType == 0" label="虚机配置 :" prop="virtualValue">
                            <el-select
                                v-model="form.virtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.virtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                    <el-form-item v-if="form.radioType == 1" label="从节点数 :">
                        <div class="virtual-step">
                            <ul>
                                <li v-for="(item, index) in form.virtualStepList" @click="addClass(((index+1)*2))" :class="{ active:((index+1)*2) == form.virtualStepCurrent}">{{item.value}}</li>
                            </ul>
                        </div>
                    </el-form-item>
                    <div class="item-node" v-if="form.radioType == 1">
                        <el-form-item
                            style="width:270px; float:left;"
                            label="主节点(master):"
                            prop="masterMirrorValue"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.masterMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.masterMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            style="width:150px; float:left; margin-left:10px;"
                            prop="masterVirtualValue"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            label-width="0"
                            >
                            <el-select
                                v-model="form.masterVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.masterVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                    <div class="item-node" v-if="form.radioType == 1">
                        <el-form-item
                            v-if="form.virtualStepCurrent == 2 || form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:270px; float:left;"
                            label="从节点(slave1):"
                            :prop="'formDomains.' + 0 + '.formMirrorValue'"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[0].formMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[0].formMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 2 || form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:150px; float:left; margin-left:10px;"
                            :prop="'formDomains.' + 0 + '.formVirtualValue'"
                            label-width="0"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[0].formVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[0].formVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 2 || form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:270px; float:left;"
                            label="从节点(slave2):"
                            :prop="'formDomains.' + 1 + '.formMirrorValue'"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[1].formMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[1].formMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 2 || form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:150px; float:left; margin-left:10px;"
                            :prop="'formDomains.' + 1 + '.formVirtualValue'"
                            label-width="0"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[1].formVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[1].formVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:270px; float:left;"
                            label="从节点(slave3):"
                            :prop="'formDomains.' + 2 + '.formMirrorValue'"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[2].formMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[2].formMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:150px; float:left; margin-left:10px;"
                            :prop="'formDomains.' + 2 + '.formVirtualValue'"
                            label-width="0"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[2].formVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[2].formVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:270px; float:left;"
                            label="从节点(slave4):"
                            :prop="'formDomains.' + 3 + '.formMirrorValue'"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[3].formMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[3].formMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 4 || form.virtualStepCurrent == 6"
                            style="width:150px; float:left; margin-left:10px;"
                            :prop="'formDomains.' + 3 + '.formVirtualValue'"
                            label-width="0"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[3].formVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[3].formVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 6"
                            style="width:270px; float:left;"
                            label="从节点(slave5):"
                            :prop="'formDomains.' + 4 + '.formMirrorValue'"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[4].formMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[4].formMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 6"
                            style="width:150px; float:left; margin-left:10px;"
                            :prop="'formDomains.' + 4 + '.formVirtualValue'"
                            label-width="0"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[4].formVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[4].formVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 6"
                            style="width:270px; float:left;"
                            label="从节点(slave6):"
                            :prop="'formDomains.' + 5 + '.formMirrorValue'"
                            :rules="{
                                required: true, message: '请选择镜像配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[5].formMirrorValue"
                                placeholder="请选择镜像配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[5].formMirrorStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item
                            v-if="form.virtualStepCurrent == 6"
                            style="width:150px; float:left; margin-left:10px;"
                            :prop="'formDomains.' + 5 + '.formVirtualValue'"
                            label-width="0"
                            :rules="{
                                required: true, message: '请选择虚机配置', trigger: 'blur'
                            }"
                            >
                            <el-select
                                v-model="form.formDomains[5].formVirtualValue"
                                placeholder="请选择虚机配置"
                                value-key="value"
                                style="float:left;">
                                <el-option
                                v-for="item in form.formDomains[5].formVirtualStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                </el-form>
                <div slot="footer" class="dialog-footer" style="text-align:center;">
                    <el-button type="primary" @click="submitForm('form')">保存</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    import BreadCrumbBack from '@/components/breadCrumbBack.vue'
    export default {
        components: {
            BreadCrumbBack
        },
        data () {
            return {
                projectName: '',
                projectTypeStatus: [
                    {
                        value: '',
                        label: '全部'
                    },
                    {
                        value: 1,
                        label: '预置'
                    },
                    {
                        value: 0,
                        label: '非预置'
                    }
                ],
                projectTypeValue: '',
                listData: [],
                currentPage:1,
                pagesize:8,
                totalCount: 0,
                dialogFormVisible: false,
                form: {
                    radioType: 1,
                    radioSource: 1,
                    mirrorStatus: [],
                    mirrorValue:'',
                    virtualStatus: [],
                    virtualValue: '',
                    virtualStepList: [
                        { value: 2 },
                        { value: 4 },
                        { value: 6 }
                    ],
                    virtualStepCurrent: 2,
                    masterMirrorStatus: [], //主节点
                    masterMirrorValue: '',
                    masterVirtualStatus: [],
                    masterVirtualValue: '',
                    formDomains: [
                        {
                            formMirrorStatus: [],
                            formMirrorValue: '',
                            formVirtualStatus: [],
                            formVirtualValue: ''
                        },
                        {
                            formMirrorStatus: [],
                            formMirrorValue: '',
                            formVirtualStatus: [],
                            formVirtualValue: ''
                        },
                        {
                            formMirrorStatus: [],
                            formMirrorValue: '',
                            formVirtualStatus: [],
                            formVirtualValue: ''
                        },
                        {
                            formMirrorStatus: [],
                            formMirrorValue: '',
                            formVirtualStatus: [],
                            formVirtualValue: ''
                        },
                        {
                            formMirrorStatus: [],
                            formMirrorValue: '',
                            formVirtualStatus: [],
                            formVirtualValue: ''
                        },
                        {
                            formMirrorStatus: [],
                            formMirrorValue: '',
                            formVirtualStatus: [],
                            formVirtualValue: ''
                        }
                    ]
                },
                projectId: '',
                addVirtualTitle: '',    //添加或修改title
                addOrmodify: '',    //添加或修改类型1添加2修改
                //表单验证
				rules: {
                    mirrorValue: [
                        { required: true, message: '请选择镜像', trigger: 'blur' }
                    ],
                    virtualValue: [
                        { required: true, message: '请选择虚机配置', trigger: 'blur' }
                    ]
                }
            }
        },
        created () {
            // this.init() //初始化
            this.initList() //初始化列表
        },
        methods: {
            init() {
                let self = this, dataUrl
                self.form.mirrorStatus = []
                self.form.mirrorValue = ''
                self.form.masterMirrorStatus = []
                self.form.masterMirrorValue = ''
                self.form.virtualStatus = []
                self.form.virtualValue = ''
                self.form.masterVirtualStatus = []
                self.form.masterVirtualValue = ''
                self.form.formDomains = [
                    {
                        formMirrorStatus: [],
                        formMirrorValue: '',
                        formVirtualStatus: [],
                        formVirtualValue: ''
                    },
                    {
                        formMirrorStatus: [],
                        formMirrorValue: '',
                        formVirtualStatus: [],
                        formVirtualValue: ''
                    },
                    {
                        formMirrorStatus: [],
                        formMirrorValue: '',
                        formVirtualStatus: [],
                        formVirtualValue: ''
                    },
                    {
                        formMirrorStatus: [],
                        formMirrorValue: '',
                        formVirtualStatus: [],
                        formVirtualValue: ''
                    },
                    {
                        formMirrorStatus: [],
                        formMirrorValue: '',
                        formVirtualStatus: [],
                        formVirtualValue: ''
                    },
                    {
                        formMirrorStatus: [],
                        formMirrorValue: '',
                        formVirtualStatus: [],
                        formVirtualValue: ''
                    }
                ]
                // if(self.form.radioType == 0){
                //     var radioType = self.form.radioType == 0 ? 1 : 2
                //     console.log()
                //     dataUrl = '/dataplatform/manage/vmConfig/vmConfigDropDownList?isInitial='+self.form.radioSource+'&mode='+radioType
                // }else{
                //     dataUrl = '/dataplatform/manage/vmConfig/vmConfigDropDownList'
                // }
                var radioType = self.form.radioType == 0 ? 1 : 2
                dataUrl = '/dataplatform/manage/vmConfig/vmConfigDropDownList?isInitial='+self.form.radioSource+'&mode='+radioType
                self.$http.get(dataUrl).then(response => {
                    let res = response.data
                    if(res.code == '200'){
                        //镜像
                        for(let i = 0; i < res.data.imageDropDownList.length; i++){
                            let mirrorJson = {}
                            mirrorJson.label = res.data.imageDropDownList[i].value
                            mirrorJson.value = res.data.imageDropDownList[i].key
                            self.form.mirrorStatus.push(mirrorJson)         //单节点镜像
                            self.form.masterMirrorStatus.push(mirrorJson)   //主节点镜像
                            for (let j = 0; j < self.form.formDomains.length; j++) {
                                self.form.formDomains[j].formMirrorStatus.push(mirrorJson)
                            }
                        }
                        //虚机
                        for(let i = 0; i < res.data.hostDropDownList.length; i++){
                            let virtuaJson = {}
                            virtuaJson.label = res.data.hostDropDownList[i].value
                            virtuaJson.value = res.data.hostDropDownList[i].key
                            self.form.virtualStatus.push(virtuaJson)        //单节点虚机
                            self.form.masterVirtualStatus.push(virtuaJson)  //主节点虚机
                            for (let j = 0; j < self.form.formDomains.length; j++) {
                                self.form.formDomains[j].formVirtualStatus.push(virtuaJson)
                            }
                        }
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })

            },
            initList() {
                let self = this
                self.$http.get('/dataplatform/manage/vmConfig/configList?pageNum='+self.currentPage+'&pagesize='+self.pagesize+'&projectName='+self.projectName+'&isPreset='+self.projectTypeValue).then((response) => {
                    let res = response.data
                    if(res.code == '200'){
                        self.listData = res.data.list
                        self.totalCount = res.data.total
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            //表格分页
			handleSizeChange: function (size) {
				this.pagesize = size;
			},
			handleCurrentChange: function(currentPage) {
                this.currentPage = currentPage
                this.initList()
            },
            //添加学生
            addFn(id) {
                let self = this
                self.addVirtualTitle = '添加虚机配置'
                self.addOrmodify = 1
                self.form.radioType = 0
                self.form.mirrorValue = ''
                self.form.virtualValue = ''
                self.form.virtualStepCurrent = 2
                self.form.masterMirrorValue = ''
                self.form.masterVirtualValue = ''
                for(let i = 0; i < self.form.formDomains.length; i++){
                    self.form.formDomains[i].formMirrorValue = ''
                    self.form.formDomains[i].formVirtualValue = ''
                }
                self.projectId = id
                self.init()
                self.dialogFormVisible = true
            },
            //修改学生
            modifyFn(item){
                let self = this
                self.addVirtualTitle = '修改虚机配置'
                self.addOrmodify = 2
                self.projectId = item.projectId
                if(item.isCluster == 0){
                    self.form.radioType = item.isCluster
                    self.form.radioSource = item.isInitial
                    self.init()
                    self.form.mirrorValue = item.mainImageId
                    self.form.virtualValue = item.mainHostId
                    for(let i = 0; i < self.form.formDomains.length; i++){
                        self.form.formDomains[i].formMirrorValue = ''
                        self.form.formDomains[i].formVirtualValue = ''
                    }
                    self.form.virtualStepCurrent = 2
                }else if(item.isCluster == 1){
                    self.form.radioType = item.isCluster
                    self.init()
                    self.form.masterMirrorValue = item.mainImageId
                    self.form.masterVirtualValue = item.mainHostId
                    self.form.virtualStepCurrent = item.cluster.length
                    for(let i = 0; i < item.cluster.length; i++){
                        self.form.formDomains[i].formMirrorValue = item.cluster[i].imageId
                        self.form.formDomains[i].formVirtualValue = item.cluster[i].hostId
                    }

                }
                self.dialogFormVisible = true
            },
            //添加学生表单提交
            submitForm(formName) {
                let self = this
				self.$refs[formName].validate((valid) => {
                    if (valid) {
                        let data = {}
                        if(self.form.radioType == 0){
                            data = {
                                projectId: self.projectId,
                                isCluster: self.form.radioType,
                                isInitial: self.form.radioSource,
                                mainImageId: self.form.mirrorValue,
                                mainHostId: self.form.virtualValue
                            }
                        }else if(self.form.radioType == 1){
                            let cluterArr = []
                            let formDomains = self.form.formDomains.slice(0,self.form.virtualStepCurrent)
                            for(let i = 0; i < formDomains.length; i++){
                                let clusterJson = {}
                                clusterJson.imageId = formDomains[i].formMirrorValue
                                clusterJson.hostId = formDomains[i].formVirtualValue
                                cluterArr.push(clusterJson)
                            }
                            data = {
                                projectId: self.projectId,
                                isCluster: self.form.radioType,
                                mainImageId: self.form.masterMirrorValue,
                                mainHostId: self.form.masterVirtualValue,
                                cluster: cluterArr
                            }
                        }
                        self.$http.post('/dataplatform/manage/vmConfig/saveConfig',data).then((response) => {
                            let res = response.data
                            if(res.code == '200'){
                                if (self.form.radioType == 0) {
                                    self.$message({
                                        message: '添加成功',
                                        type: 'success'
                                    })
                                }else{
                                    self.$message({
                                        message: '修改成功',
                                        type: 'success'
                                    })
                                }

                                self.initList()
                                self.dialogFormVisible = false
                                self.$refs[formName].resetFields()
                            }else if(res.code == '401'){
                                self.$router.replace({
                                    path:'/login'
                                })
                            }else{
                                self.$message.error(res.message)
                            }
                        })
                    }
                })
            },
            //弹窗step切换
            addClass:function(index){
                this.form.virtualStepCurrent = index
            },
            //搜索
            searchFn() {
                this.currentPage = 1
                this.initList()
            }
        }
    }
</script>
